// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { ListView } from "std-widgets.slint";

export component TestCase {
    width: 300phx;
    height: 300phx;
    in-out property<[int]> model: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];

    function assert(cond: bool, error: string) {
        if (!cond && root.error == "") {
            root.error = error;
        }
    }

    out property <int> clicked;
    out property <string> error;

    ListView {
        viewport-y: -530px;
        for val[i] in model: TouchArea {
            height: 100px;
            clicked => {
                assert(i == 6, "i = " + i + " ≠ 6");
                assert(val == 6, "val = " + val + " ≠ 6");
                val += 100;
                assert(val == 106, "val = " + val + " ≠ 106");
                model[i] += 1000;
                assert(val == 1106, "val = " + val + " ≠ 1106");
                root.clicked = val;
            }
        }
    }

}

/*
```rust
let instance = TestCase::new().unwrap();

slint_testing::send_mouse_click(&instance, 50., 155.);
assert_eq!(instance.get_error().as_str(), "");
assert_eq!(instance.get_clicked(), 1106);
```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;

slint_testing::send_mouse_click(&instance, 50., 155.);
assert_eq(instance.get_error(), "");
assert_eq(instance.get_clicked(), 1106);

```


```js
var instance = new slint.TestCase({});
slintlib.private_api.send_mouse_click(instance, 50., 155.);


assert.equal(instance.error, "");
assert.equal(instance.clicked, 1106);
```


*/
